package com.loong.nnm.controller;

import com.loong.nnm.entity.alarm.AlarmMaskState;
import com.loong.nnm.entity.alarm.TcaParameter;
import com.loong.nnm.entity.devm.NtpParameter;
import com.loong.nnm.entity.netconf.NetconfBuilderParameters;
import com.loong.nnm.entity.performance.Performance;
import com.loong.nnm.services.*;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/restconf/config/network-topology:network-topology/topology/topology-netconf")
public class ODLController {

    @Resource
    NetconfToolServices netconfToolServices;

    @RequestMapping("/node/{node}")
    public String setNode(@PathVariable String node, @RequestBody NetconfBuilderParameters parameters) {
        System.out.println(parameters);
        System.out.println("创建连接调用");
        if (netconfToolServices.createConnection(parameters) == 1) return "201 OK";
        return "404 ERROR";
    }


    @Resource
    DevmServices devmServices;

    @RequestMapping("/node/{node}/ntp")
    public String setNtp(@PathVariable String node, @RequestBody NtpParameter ntpParameter) {
        return devmServices.configNtpServers(node, ntpParameter);
    }

    @GetMapping("/node/{node}/yang-ext:mount/acc-devm:me")
    public String getMe(@PathVariable String node) {
        System.out.println(node);
        return devmServices.getMe(node);
    }


    @GetMapping("/node/{node}/yang-ext:mount/acc-devm:eqs")
    public String getEqs(@PathVariable String node) {
        System.out.println(node);
        return devmServices.getEqs(node);
    }

    @GetMapping("/node/{node}/yang-ext:mount/acc-devm:ptps")
    public String getPtps(@PathVariable String node) {
        System.out.println(node);
        return devmServices.getPtps(node);
    }

    @GetMapping("/node/{node}/yang-ext:mount/acc-devm:ftps")
    public String getFtps(@PathVariable String node) {
        System.out.println(node);
        return devmServices.getFtps(node);
    }

    @GetMapping("/node/{node}/yang-ext:mount/acc-devm:ctps")
    public String getCtps(@PathVariable String node) {
        System.out.println(node);
        return devmServices.getCtps(node);
    }


    @Resource
    AlarmsServices alarmsServices;

    @RequestMapping("/node/{node}/yang-ext:mount/acc-alarms:alarm-mask-states")
    public String setAlarmMaskState(@PathVariable String node, @RequestBody AlarmMaskState alarmMaskState) {
        return alarmsServices.setAlarmMaskState(node, alarmMaskState);
    }

    @GetMapping("/node/{node}/yang-ext:mount/acc-alarms:alarms")
    public String getAlarms(@PathVariable String node) {
        System.out.println(node);
        return alarmsServices.getAlarms(node);
    }

    @GetMapping("/node/{node}/yang-ext:mount/acc-alarms:alarm-mask-states")
    public String getAlarmMasks(@PathVariable String node) {
        System.out.println(node);
        return alarmsServices.getAlarmMaskState(node);
    }

    @GetMapping("/node/{node}/yang-ext:mount/acc-alarms:tcas")
    public String getTcas(@PathVariable String node) {
        System.out.println(node);
        return alarmsServices.getTca(node);
    }

    @GetMapping("/node/{node}/yang-ext:mount/acc-alarms:tca-parameters")
    public String getTcaParameters(@PathVariable String node) {
        System.out.println(node);
        return alarmsServices.getTcaParameters(node);
    }

    @Resource
    PerformanceServices performanceServices;

    @GetMapping("/node/{node}/yang-ext:mount/acc-performance:performances")
    public String getPerformances(@PathVariable String node) {
        System.out.println(node);
        return performanceServices.getPerformances(node);
    }

    @GetMapping("/node/{node}/performances/current")
    public String getCurrentPerformances(@PathVariable String node, @RequestBody Performance performance) {
        System.out.println(node);
        return performanceServices.getCurrentPerformances(node, performance);
    }

    @RequestMapping("/node/{node}/yang-ext:mount/acc-performance:get-history-performance-monitoring-data")
    public String getHistoryPerformances(@PathVariable String node, @RequestBody Performance performance) {
        System.out.println(node);
        System.out.println("=============================================");
        System.out.println(performance);
        System.out.println("=============================================");
        return performanceServices.getHistoryPerformances(node, performance);
    }


    @Resource
    PGServices pgServices;

    @GetMapping("/node/{node}/yang-ext:mount/acc-protection-group:pgs")
    public String getPGs(@PathVariable String node) {
        System.out.println(node);
        return pgServices.getPGs(node);
    }

    @GetMapping("/node/{node}/yang-ext:mount/acc-protection-group:lagPGs")
    public String getLAGs(@PathVariable String node) {
        System.out.println(node);
        return pgServices.getLAGs(node);
    }

    @Resource
    XCServices xcServices;

    @GetMapping("/node/{node}/connections")
    public String getConnections(@PathVariable String node) {
        System.out.println(node);
        return xcServices.getConnections(node);
    }
}